Skip to content

fix(cloudhypervisor): a Windows clone or restore resumes from the snapshot's clock - #341

Merged
CMGS merged 2 commits into
cocoonstack:masterfrom
zili-simular:windows-restore-keep-clock
Nov 27, 2026
Merged

CMGS merged 2 commits into
cocoonstack:masterfrom
zili-simular:windows-restore-keep-clock

Conversation

@zili-simular

@zili-simular zili-simular commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What

cocoon vm clone and cocoon vm restore send "clock_restore_mode": "Preserve" in the vm.restore request for a Windows guest. The guest then resumes from the snapshot's clock: its uptime continues from the snapshot, and its date and time are behind by the snapshot's age until something sets them in the guest.

 cocoon vm clone / cocoon vm restore
   launch CH
-  vm.restore {source_url, memory_restore_mode}
+  vm.restore {source_url, memory_restore_mode, clock_restore_mode: "Preserve"}   # Windows guest
+  vm.restore {source_url, memory_restore_mode}                                   # Linux guest, and any migration receive
   hot-swap NICs, add disks
   vm.resume
  • Linux guests keep Cloud Hypervisor's default (advance by the snapshot's age).
  • A vm migrate receive keeps the default too: the gap is the seconds of the handoff, and advancing keeps the guest's date right.
  • vm clone prints the Set-Date step with its other Windows hints. docs/windows.md has the section.

Why

A Windows guest restored with the default moves its uptime forward by the snapshot's age. When that jump is 2^31 to 2^32 ms (24.9 to 49.7 days) the guest can come back unable to retransmit TCP: it sends a segment once and never again (cocoonstack/cloud-hypervisor#9). The guest looks healthy otherwise, so the failure is silent, and a snapshot taken from such a guest hands the fault to its clones. A date that is behind fails loudly (TLS) and one command in the guest fixes it.

Changes against the first version of this PR

  • The field. The first version sent clock_catchup: false, the option of vmm: Add clock_catchup to the restore config cloud-hypervisor#10. Upstream has since taken the same idea as clock_restore_mode (Advance or Preserve), and the fork dropped its own patch when it rebased on 2026-11-27. On the current dev build the old field is ignored, so the first version changed nothing there. Both clear KVM_CLOCK_REALTIME before KVM_SET_CLOCK and skip the TSC advance, so the mechanism the original evidence measured is the one this version asks for.
  • One owner for the rule. restoreClockMode(vmCfg, migrationReceive) decides for both call sites; restoreVM takes the mode. The first version had a *bool field, a forwarder over vmCfg.Windows and the migration exception spelled at one call site.
  • The clone hint, and the test moved next to the other restoreAndResumeClone tests.
  • Rebased on master (the test it sat beside was removed by test: drop a duplicated case, a dead assertion and two shims; tag a linux-only test #345).

The decision this PR makes

Windows guests always preserve; there is no flag. The first version asked whether this should be opt-in, or whether cocoon should set the date through the guest agent.

  • Not opt-in: the default would stay the silent failure, and every Windows deployment would have to learn about the flag from an incident.
  • Not the agent: setting a guest's date is guest policy, and cocoon already leaves the post-clone network setup to the guest and prints the commands.
  • Cost: a deployment that relied on the restore for the date now gets a Windows guest that is behind until it runs Set-Date. It needs a control-plane step it did not need before.

For downstream

Requirements

A Cloud Hypervisor that knows clock_restore_mode: upstream from 2026-11-23, the cocoonstack dev build from v56.0.0-dev-5fd961f7. An older one ignores the field and advances the clock, as today.

Size and cost

  • Production code +23 / -4, net +19: utils.go +17 / -2 (the mode type and constant, the field, restoreClockMode), clone.go and restore.go one changed line each, clonehints.go +4.
  • Tests +51. Docs +8.
  • Hot paths: one string field in the vm.restore body. No added call, no added wait.

Gates: golangci-lint 0 issues on linux and darwin, fmt, vet, go mod tidy -diff, asl on both; go test -race on darwin (39 packages) and in a linux container (40 packages).

Coverage

Hardware for the rows marked so: bare metal, x86_64, kernel 6.12; Cloud Hypervisor from the cocoonstack dev build v56.0.0-dev-5fd961f7; Windows 11 25H2, 2 vCPU / 4G, no NIC, read over vsock exec. Candidate is this branch (2402701), control is master (b780388). The contrasts and thresholds were written down before the run: 31 checks, 0 failures.

Case How Result
Windows clone, 300 s after the snapshot hardware, control and candidate control: guest uptime moved 310 s over 309 s of host time, date unchanged against the host. Candidate: uptime moved 4 s over a 314 s gap, date 310 s behind; vm clone printed the Set-Date step, and after it the guest was 2 s from the host
Windows vm restore to the same snapshot hardware, control and candidate control: uptime moved 326 s over 326 s. Candidate: uptime moved 4 s over 330 s, date 326 s behind
Windows vm hibernate, 300 s, wake by vm restore hardware, candidate uptime moved 3 s over 305 s, date 303 s behind
Linux clone, 120 s after the snapshot hardware, candidate guest date 1 s from the host: the default stays
vm.restore body: Linux clone, Windows clone, Windows migration receive unit test no field, "Preserve", no field
Windows clone hints carry the Set-Date step; Linux hints do not unit test covered
The TCP symptom on a 28-day-old Windows snapshot (uptime and SYN count) hardware, by the original author, with the fork's clock_catchup=false on v0.7.1 uptime 162 s instead of 28.02 days; 3 SYNs instead of 1; 4 of 4 clones. Same KVM mechanism as Preserve
A snapshot aged 28 days on this branch not run the round's script could not find the saved clock in this build's state.json, so it skipped the cell
Windows vm migrate unit test only the receive sends no field

zili-simular and others added 2 commits November 27, 2026 23:13
…pshot's clock

Cloud Hypervisor advances the guest clock by the snapshot's age on
restore, which moves a Windows guest's uptime forward by the same
amount. When that jump is 2^31 to 2^32 ms (24.9 to 49.7 days), the
guest can resume with its TCP retransmission timers stopped
(cocoonstack/cloud-hypervisor#9).

Send clock_catchup=false with vm.restore for a Windows clone and
restore. The guest's date is then behind by the snapshot's age until
something sets it in the guest. A migration receive still catches up,
and a Cloud Hypervisor without the option ignores the field.
…oud Hypervisor has now

The clock_catchup field this branch sent is gone: upstream took the same idea as clock_restore_mode (advance or preserve) and the fork dropped its patch for it, so the field was ignored and a Windows restore advanced the clock as before.

One function, restoreClockMode, owns the rule for both call sites: a Windows clone and a Windows restore preserve, a migration receive and every Linux guest keep the default. vm clone prints the Set-Date step with its other Windows hints, and the test moves next to the other restoreAndResumeClone tests.
@CMGS
CMGS force-pushed the windows-restore-keep-clock branch from 1c90d04 to 2402701 Compare November 27, 2026 17:18
@CMGS
CMGS merged commit c76a7e3 into cocoonstack:master Nov 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants